<extend name="./public/frame.html"/>
<block name="content">
    <script type="text/javascript" charset="utf-8" src="/public/editor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/public/editor/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="/public/editor/lang/zh-cn/zh-cn.js"></script>
    <form class="layui-form layui-form-pane1" action="" method="post">
        <input type="hidden" name="commodity_id" value="{$data.commodity_id}">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">商品类型</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <select name="commodity_type">
                        <option value="0" <if condition="$data['commodity_type'] eq 0"> selected </if>>虚拟商品</option>
                        <option value="1" <if condition="$data['commodity_type'] eq 1"> selected </if>>实物商品</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">商品分类</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <select name="commodity_classification" id="commodity_classification">
                        <volist name="cate" id="v">
                            <option value="{$v.classification_id}" <if condition="$data['commodity_classification'] eq $v.classification_id"> selected </if>>{$v.classification_name}</option>
                        </volist>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-block">
                <input type="text" name="commodity_name" lay-verify="required|commodity_name" required placeholder="请输入商品名称"
                       autocomplete="off" class="layui-input" value="{$data.commodity_name}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商品图片</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="test1">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
            </div>
        </div>
        <div class="layui-form-item" id="img_url">
            <label class="layui-form-label"> </label>
            <div class="layui-input-block">
                <img src="{$data.commodity_picture}" alt="" style="width: 400px;height: 300px">
                <input type="hidden" name="commodity_picture" value="{$data.commodity_picture}">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">开始日期</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input type="text" name="valid_start_time" lay-verify="required|valid_start_time" class="layui-input" id="test6-1" value="{$data['valid_start_time']}">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">结束日期</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input type="text" name="valid_end_time" lay-verify="required|valid_end_time" class="layui-input" id="test6-2" value="{$data['valid_end_time']}">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">兑换积分</label>
            <div class="layui-input-block">
                <input type="text" name="need_integral" lay-verify="required|need_integral" required placeholder="请输入兑换积分"
                       autocomplete="off" class="layui-input" value="{$data.need_integral}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">总库存</label>
            <div class="layui-input-block">
                <input type="text" name="number" lay-verify="required|number" required placeholder="请输入总库存"
                       autocomplete="off" class="layui-input" value="{$data.number}">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <select name="is_use" id="is_use">
                        <option value="1" <if condition="$data['is_use'] eq 1"> selected </if>>已上架</option>
                        <option value="0" <if condition="$data['is_use'] eq 0"> selected </if>>未上架</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" lay-verify="required|sort" required placeholder="请输入排序"
                       autocomplete="off" class="layui-input" value="{$data.sort}">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">兑换规则</label>
                <div class="layui-input-block">
                    <script name="change_the_rules" id="editor" type="text/plain" style="width:960px;height:300px;">{$data.change_the_rules}</script>
                    </div>
                    </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                        <button class="layui-btn" type="button" id="submits">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                        </div>
                        </form>
                        <script>
                        layui.use(['form', 'laydate', 'upload'], function () {
                            var form = layui.form;
                            var laydate = layui.laydate;
                            var upload = layui.upload;
                            //执行实例
                            var uploadInst = upload.render({
                                elem: '#test1' //绑定元素
                                , url: '{:url("upload")}' //上传接口
                                , done: function (res) {
                                    if (res.status == 1) {
                                        $("#img_url").find('img').attr('src', res.data.file);
                                        $("#img_url").find('input').val(res.data.file);
                                        $("#img_url").show();
                                        form.render();
                                    }
                                }
                                , error: function (res1) {
                                    console.log(res1);
                                    //请求异常回调
                                }
                            });

                            //墨绿主题
                            laydate.render({
                                elem: '#test6-1' //指定元素
                                , type: 'datetime'
                                , theme: 'molv'
                                //,range: true
                                , trigger: 'click'
                            });

                            laydate.render({
                                elem: '#test6-2' //指定元素
                                , type: 'datetime'
                                , theme: 'molv'
                                //,range: true
                                , trigger: 'click'
                            });

                            form.on('checkbox', function (data) {
                                var type = $(this).data('type');
                                if (type == 'all') {
                                    var child = $('.fa').find('.item_child');
                                    child.each(function (index, item) {
                                        item.checked = data.elem.checked;
                                    });
                                    form.render('checkbox');

                                }
                            });

                            //监听提交
                            $(document).on('click', '#submits', function () {

                                $('form').submit();
                            })

                        });

                    </script>
                    <script type="text/javascript">
                        var ue = UE.getEditor('editor',{
                            zIndex : 0,// z轴
                        });
                    </script>
</block>
